package global.com.loansapplication.ui.actviity.user;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.EditText;
import android.widget.TextView;

import com.jakewharton.rxbinding.view.RxView;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import butterknife.Bind;
import global.com.loansapplication.R;
import global.com.loansapplication.base.BaseActivity;
import global.com.loansapplication.event.NetErrorEvent;
import global.com.loansapplication.ui.actviity.user.biz.ForgetPwdBiz;
import global.com.loansapplication.ui.actviity.user.component.DaggerForgetComponent;
import global.com.loansapplication.ui.actviity.user.contract.ForgetContract;
import global.com.loansapplication.ui.actviity.user.module.ForgetModule;
import global.com.loansapplication.ui.actviity.user.presenter.ForgetPwdPresenter;
import rx.functions.Action1;

/**
 * Created by admin on 2017/12/2.
 */

public class ForgetPwdAct extends BaseActivity implements ForgetContract.View {


    @Bind(R.id.pwd_old)
    EditText pwdOld;
    @Bind(R.id.pwd_new)
    EditText pwdNew;
    @Bind(R.id.pwd_new_sure)
    EditText pwdNewSure;
    @Bind(R.id.suggetion_submit)
    TextView submit;
    @Inject
    ForgetPwdPresenter presenter;
    @Inject
    ForgetPwdBiz biz;

    @Override
    protected void setRoot() {
        setTitleBar("#FFFFFFFF");
        setContentView(R.layout.activity_forget_pwd);

    }

    @Override
    protected void setup() {
        setStateText();
        setToolBar("重置密码", "");
        DaggerForgetComponent.builder().forgetModule(new ForgetModule(this)).build().inject(this);
        presenter.setBiz(biz);

    }


    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        RxView.clicks(submit)
                .compose(this.<Void>bindToLifecycle())
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        presenter.resetPwd(pwdOld.getText().toString().trim(), pwdNew.getText().toString().trim(), pwdNewSure.getText().toString().trim());
                    }
                });
    }


    @Override
    public void onNetErrorEvent(NetErrorEvent event) {
        super.onNetErrorEvent(event);
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }
    /***
     * Stop location service
     */
    @Override
    protected void onStop() {

        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        biz.onDestory();

    }

}
